home *** CD-ROM | disk | FTP | other *** search
- /*
- File: OXFuncs.cpp
-
- Contains: OpenDoc™ launcher code shared between old and new launcher
-
- Owned by: Nick Pilch
-
- Copyright: © 1996 - 1997 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <13> 1/8/97 DH 1401434: Properly check for read-only docs
- in StartDocSizeChangeProcess.
- <12> 12/18/96 DH 1375780: Now handles case of opening doc
- with large doc size that is read only.
- <11> 10/23/96 DH Fixed up another build break problem.
- <10> 10/23/96 DH Added function prototype to fix problem
- with previous checkin.
- <9> 10/22/96 DH 1333949 • Misleading out of memory message
- from sample parts. 1336808 • OpenDoc 1.0.4:
- does not run when memory is set to high
- value. Check if a document process couldn't
- be started because of out-of-mem. If so,
- start doc heap size change process via new
- event to OD shell.
- <8> 7/11/96 eeh 1363971: plug memory leaks
- <7> 6/23/96 NP 10002: Launch time speedups.
- <6> 6/14/96 NP 10002: Launch time speedups
- <5> .06.1996 NP 10002: Launch time fixes, system process.
- <4> .05.1996 NP Reverting.
- <3> .05.1996 NP 10002: Launch time fixes.
- <2> .05.1996 NP Revised HandleLaunchFailed.
- <1> .05.1996 NP first checked in
-
- To Do:
- In Progress:
-
- */
-
-
- #ifndef _ODXFUNCS_
- #include "ODXFuncs.h"
- #endif
-
- #ifndef _ODPRCS_
- #include "ODPrcs.h"
- #endif
-
- //#ifndef _SPDEFS_
- //#include "SPDefs.h"
- //#endif
-
- //#ifndef _SHELLDEF_
- //#include "ShellDef.h"
- //#endif
-
- #ifndef _ODXDPFNS_
- #include "ODXDpFns.h"
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef _SHELLDEF_
- #include "ShellDef.h"
- #endif
-
- #ifndef __ICONS__
- #include <Icons.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- //==============================================================================
- // Macros
- //==============================================================================
-
- #define CHECK(EXPR) if((err=(EXPR)) == noErr) ; else return err
-
- //==============================================================================
- // Function Prototypes
- //==============================================================================
-
- OSErr StartDocSizeChangeProcess(FSSpec* theFSSpec,DescType evtID);
-
- //------------------------------------------------------------------------------
- // HandleLaunchFailed
- //------------------------------------------------------------------------------
-
- pascal OSErr HandleLaunchFailed( const AppleEvent* ae, AppleEvent* /*reply*/,
- long /*refCon*/ )
- {
- // This is an Apple Event handler that catches launch-failed events.
-
- long launchError;
- Str255 appName, libName;
-
- GetLaunchFailedParams(ae, launchError, NULL, appName, libName);
-
- // THIS HAPPENS IN THE NORMAL COURSE OF QUITTING A PROCESS
- // if( launchError == noErr )
- // WARN("HandleLaunchFailed: Got an app-died event, but error is noErr.");
-
- if (launchError != noErr)
- NotifyLaunchFailed(launchError, appName, libName);
-
- return noErr;
- }
-
- //------------------------------------------------------------------------------
- // HandleRequiredEvent
- //------------------------------------------------------------------------------
-
- pascal OSErr HandleRequiredEvent(const AppleEvent *theAppleEvent,
- AppleEvent* /*reply*/, long /*refCon*/)
- {
- AEDescList documentList = {typeNull, NULL};
- long documentCount;
- OSErr err = noErr;
- FSSpec theFSSpec;
-
- // GetOpenDocBinaryFileSpec(kODNULL); // Sets up CFM search paths.
-
- CHECK(AEGetParamDesc(theAppleEvent,keyDirectObject,typeAEList,&documentList));
- CHECK(AECountItems(&documentList,&documentCount));
- DescType evtID;
- DescType ignoreType;
- Size ignoreActual;
- CHECK( AEGetAttributePtr( theAppleEvent, keyEventIDAttr, typeType,
- &ignoreType, &evtID, sizeof(evtID), &ignoreActual ));
-
- err = noErr;
-
- FSSpec seedFSSpec;
- seedFSSpec.name[0] = 0;
-
- AEDesc documentDesc = {typeNull, NULL};
-
- while (documentCount && (err == noErr))
- {
- AEKeyword theAEKeyword;
-
- CHECK(AEGetNthDesc(&documentList, documentCount, typeWildCard,
- &theAEKeyword, &documentDesc));
- if( GetDescFSSpec(&documentDesc,theFSSpec) != noErr )
- theFSSpec.name[0] = 0;
- err = VerifyAndLaunchDocumentStub(&documentDesc, kODNULL,
- kODNULL, evtID, &seedFSSpec);
- if( err == memFullErr || err == memFragErr)
- {
- err = StartDocSizeChangeProcess(&theFSSpec,evtID);
- }
- if ( --documentCount )
- (void)AEDisposeDesc( &documentDesc );
- }
- (void)AEDisposeDesc( &documentList );
-
- if (seedFSSpec.name[0] != 0)
- err= LaunchDocumentStub(&documentDesc, &seedFSSpec, kODNULL,
- kODNULL, kODNULL, evtID);
- (void)AEDisposeDesc( &documentDesc );
-
- if (err)
- ReportDocumentError(theFSSpec.name, err);
- else
- DocumentLaunched();
-
- return err;
- }
-
- OSErr StartDocSizeChangeProcess(FSSpec* theFSSpec,DescType evtID)
- {
- // This function deals with the problem where a document has a custom
- // size which makes it too big to open in available memory. Because
- // OpenDoc requires you to open a document to change its size, this
- // could lead to unopenable documents. So, we allow the user to change
- // the size here and open the document again.
- // To implement this, it launches the document like it would normally,
- // but passes a different event that tells OpenDoc to let the user lower
- // the size of the document. After finishing this, OpenDoc sends an
- // event back to the System Process that closes and opens the document
- // again.
- OSErr err = noErr;
-
- ODHandle size0 = kODNULL;
- ODHandle size1 = kODNULL;
- ODSShort prefResFile = 0;
- short numSizeRsrcs = 0;
- ODBoolean dontClose = kODFalse;
- ODBoolean isReadOnly = kODFalse;
- ODHandle errString = kODNULL;
-
- // First, check to see if the file is read-only. If it is, the user cannot
- // change the size, so put up an alert with some suggestions on how to open
- // the document.
- err = FileIsReadOnly(theFSSpec, &isReadOnly);
- if( err== noErr )
- {
- if( isReadOnly )
- {
- errString = Get1Resource('STR ', kODSPStrCannotOpenRODocSizeErrMsg);
- HLock( errString );
- ReportErrorGeneric( (unsigned char*)*errString);
- ReleaseResource(errString);
- }
- else
- {
- short theCurResFile = CurResFile();
- prefResFile = FSpOpenResFile((const FSSpec *)theFSSpec,fsRdWrPerm);
-
- if (prefResFile != -1)
- {
- numSizeRsrcs = Count1Resources(kSIZERsrcType);
- // If there is a preferred size resource, there will be SIZE 0 & 1
- // in addition to the SIZE -1 resource.
- if( numSizeRsrcs > 1 )
- {
- // Save current size of document in temp resource, and set size of
- // document to default minimum size.
- err = ReplaceResourceWithNewType( kSIZERsrcType, kODTempSizeRsrcType, 0 );
- err = ReplaceResourceWithNewType( kSIZERsrcType, kODTempSizeRsrcType, 1 );
-
- CloseResFile( prefResFile );
- UseResFile(theCurResFile);
- dontClose = kODTrue;
-
- // Create Apple Event of type "DocSizeDialog" to pass to LaunchApplication .
- AEAddressDesc myAddress;
- myAddress.descriptorType = 'null';
- myAddress.dataHandle = NULL;
- AppleEvent theEvent;
- err = AECreateAppleEvent( 'dumb', 'hack', &myAddress,
- kAutoGenerateReturnID, kAnyTransactionID, &theEvent);
- err = AEPutParamPtr( &theEvent, 'docs', typeFSS, theFSSpec, sizeof(FSSpec) );
-
- AEDesc launchDesc;
- err = AECoerceDesc(&theEvent, typeAppParameters, &launchDesc);
-
- HLock(launchDesc.dataHandle);
- LaunchParamBlockRec launchPB;
- launchPB.launchBlockID = extendedBlock;
- launchPB.launchEPBLength = extendedBlockLen;
- launchPB.launchControlFlags = launchContinue | launchNoFileFlags | launchUseMinimum;
- launchPB.launchAppSpec = theFSSpec;
- launchPB.launchAppParameters = (AppParametersPtr)*(launchDesc.dataHandle);
-
- // Launch document process that will allow the user to change the size of the document.
- err = LaunchApplication(&launchPB);
- }
- if( dontClose == kODFalse )
- {
- CloseResFile( prefResFile );
- UseResFile(theCurResFile);
- }
- }
- }
- }
- return err;
- }
-
-
-